package com.example.demo.lc;

public class Lc513 {
    static int curVal = 0;
    static int curHeight = 0;

    public static void main(String[] args) {
        TreeNode treeNode5 = new TreeNode(5);
        TreeNode treeNode4 = new TreeNode(4);
        TreeNode treeNode2 = new TreeNode(2,null,null);
        TreeNode treeNode3 = new TreeNode(3,treeNode4,treeNode5);
        TreeNode treeNode1 = new TreeNode(1,treeNode2,treeNode3);
        System.out.println(findBottomLeftValue(treeNode1));
    }

    public static int findBottomLeftValue(TreeNode root) {
        int height = 0;
        dfs(root,height);
        return curVal;
    }

    private static void dfs(TreeNode root, int height) {
        if(root == null){
            return;
        }
        height++;
        dfs(root.left,height);
        dfs(root.right,height);
        if(height > curHeight){
            curHeight = height;
            curVal = root.val;
        }
    }


}
